<template>
	<view class="perCenter">
		<view class="header">
			<view class="header-img">
				<view class="img">
					<image :src="userInfo.avatar" v-if="userInfo.avatar"></image>
					<image src="@/static/image/my/defalut.png" v-else></image>
				</view>
				<view class="text">
					<view class="name">{{userInfo.nickName}}</view>
					<view class="tip">
						{{roles}} |
						{{userInfo.dept.deptName}}
					</view>
				</view>
			</view>
			<view class="header-btns">
				<view class="left" @click="navTo('/subPages/editPassword/index')">
					<view class="icon">
						<image src="@/static/image/my/icon01.png"></image>
					</view>
					<view class="text">
						修改密码
					</view>
				</view>
				<view class="right" @click="hanldeOut">
					<view class="icon">
						<image src="@/static/image/my/icon02.png"></image>
					</view>
					<view class="text">
						退出登录
					</view>
				</view>
			</view>
		</view>
		<u-modal :show="showConfirm" @cancel="showConfirm=false" @confirm="outLogin" :showCancelButton="true"
			title="提示" content='是否确认退出?'></u-modal>
	</view>
</template>

<script>
	export default {
		components: {

		},
		filters: {

		},
		data() {
			return {
				userInfo: {},
				roles: '',
				showConfirm:false
			}
		},
		onShow() {
			const userInfo = uni.getStorageSync('user_info')
			if (userInfo) {
				this.userInfo = userInfo?.user
				let roles = []
				if (this.userInfo?.roles) {
					for (let i = 0; i < this.userInfo?.roles.length; i++) {
						roles.push(this.userInfo?.roles[i].roleName)
					}
					this.roles = roles.toString()
				}
			}
		},
		created() {

		},
		methods: {
			navTo(url) {
				uni.navigateTo({
					url: url
				})
			},
			hanldeOut(){
				this.showConfirm=true
			},
			outLogin() {
				this.showConfirm=false
				uni.redirectTo({
					url: '/subPages/login/index',
					success: res => {
						uni.clearStorageSync();
					}
				});
			}

		}
	}
</script>

<style lang="scss" scoped>
	.perCenter {
		background: url('@/static/image/my/bg.png') no-repeat center top;
		background-size: 100% auto;
		width: 100vw;

		.header {
			padding: 176rpx 30rpx;

			.header-img {
				display: flex;
				align-items: center;
				margin-bottom: 77rpx;

				.img {
					width: 100rpx;
					height: 100rpx;
					border-radius: 50%;
					margin-right: 30rpx;

					image {
						width: 100rpx;
						height: 100rpx;
						border-radius: 50%;
					}
				}

				.text {
					.name {
						font-size: 34rpx;
						font-weight: 500;
						color: #323232;
					}

					.tip {
						font-size: 26rpx;
						font-weight: 400;
						color: #909399;

					}
				}
			}

			.header-btns {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.left {
					width: 332rpx;
					height: 130rpx;
					background: rgba(54, 133, 230, 0.2);
					border-radius: 12rpx;
					display: flex;
					padding: 25rpx 30rpx;
					box-sizing: border-box;
					align-items: center;

				}

				.right {
					width: 332rpx;
					height: 130rpx;
					background: rgba(255, 154, 102, 0.19);
					border-radius: 12rpx;
					display: flex;
					padding: 25rpx 30rpx;
					box-sizing: border-box;
					align-items: center;
				}

				.icon {
					width: 80rpx;
					height: 80rpx;
					margin-right: 25rpx;

					image {
						width: 80rpx;
						height: 80rpx;
					}
				}

				.text {
					font-size: 28rpx;
					font-weight: 500;
					color: #323232;
				}
			}
		}

	}
</style>
